package com.xmx.ordercenter.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmx.common.utils.PageUtils;
import com.xmx.common.utils.Query;

import com.xmx.ordercenter.dao.CartDao;
import com.xmx.ordercenter.entity.CartEntity;
import com.xmx.ordercenter.service.CartService;

import javax.annotation.Resource;


@Service("cartService")
public class CartServiceImpl extends ServiceImpl<CartDao, CartEntity> implements CartService {

    @Resource
    CartDao cartDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CartEntity> page = this.page(
                new Query<CartEntity>().getPage(params),
                new QueryWrapper<CartEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CartEntity queryExist(Integer goodsId, Integer productId, Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("goods_id",goodsId);
        queryWrapper.eq("product_id",productId);
        CartEntity cartEntity = cartDao.selectOne(queryWrapper);
        return cartEntity;
    }

}